<template>
	<view class="lottery_container">
		<view class="grid_wrap">
			<view class="lottery_wrap">
				<ul class="lottery_grid">
					<li v-for="(item, index) in grid_info_arr" :class="{ active: current_index == index && index != 8 }" :key="index"
					  :data-index="index">
						<image v-if="item.prizeType==1" class="grid_img" mode='aspectFit' src="https://tcjyh2022.oss-cn-hangzhou.aliyuncs.com/wechat/csqx_zhong.png" ></image>
							<image v-else-if="item.prizeType==2" mode='aspectFit' src="@/static/coupon_active.svg" ></image>
							<image v-else-if="item.prizeType==3" mode='aspectFit' src="@/static/mine/jifen.svg" ></image>
							<image v-else mode='aspectFit' src="@/static/index/hb.svg" ></image>
							
							{{ index == 8 ? '抽奖' : item.title }}
					</li>
					<li  class="active" 
					 @click="luck_draw" data-index="8">
						
							抽奖
					</li>
				</ul>
			</view>
			<view class="lottery_wrap_border">
				<ul v-for="(item, index) in 4" :key="index">
					<li v-for="(item, index) in 12" :key="index"></li>
				</ul>
			</view>
		</view>
		<!-- 抽奖完成弹出的窗口 -->
		<!-- <view class="lottery_finish_wrap">
			
		</view> -->
	</view>

</template>

<script>
	import LotteryDraw from './SJ-LotteryDraw.js';
	let grid_info = [];
	export default {
		data() {
			return {
				current_index: -1,
			};
		},
		props: {
			grid_info_arr: {
				type: Array,
				default: function() {
					return grid_info
				}
			},
		},
		onLoad() {
		},

		methods: {
			luck_draw(event) {
				let index = event.currentTarget.dataset.index;
				console.log('aa'+index)
				let that = this
				this.$emit('get_winingIndex', function(res){
					console.log(res);
					let lottery_draw_param=res;
					let win = new LotteryDraw({
							domData: that.grid_info_arr,
							...lottery_draw_param
						},
						function(index, count) {
							that.current_index = index;
							console.log()
							if (lottery_draw_param.winingIndex == index && lottery_draw_param.totalCount == count) {
								that.$emit('luck_draw_finish', that.grid_info_arr[index])
								 console.log('抽到了')
							}
						}
					);
				});
				
			}
		}
	};
</script>

<style scoped lang="css">
	@import './SJ-LotteryDraw.css';
</style>
